import { SkillRuneComposeComfirmStuffIcon } from "./SkillRuneComposeComfirmStuffIcon";
import { ItemsUtil } from "../../../shortcuts/item/ItemsUtil";
import { EPlayerItemPosType } from "../../../../../../Message/Public/EPlayerItemPosType";
import { ItemData } from "../../../../resource/info/ItemData";
import { RuneUtil } from "../RuneUtil";
import { Language } from "../../../../../../extend/language/Language";
import { Cache } from "../../../../cache/Cache";
import { ItemInfo } from "../../../../resource/info/ItemInfo";
import { ObjCreate } from "../../../common/ObjCreate";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class SkillRuneComposeConfirmSubWin
    
    export  class SkillRuneComposeConfirmSubWin /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public getCurSelectedIcon(): SkillRuneComposeComfirmStuffIcon
        {
            if (this.isNull) 
            {
                return null;
            }
            return this._curIcon;
        }

        public updateSelected(arg1: SkillRuneComposeComfirmStuffIcon): void
        {
            if (this._curIcon != null) 
            {
                this._curIcon.clearSelectedView();
            }
            this._curIcon = arg1;
            this._curIcon.setSelectedView();
            var loc1=arg1.itemData;
            if (!ItemsUtil.isBind(this._target) && ItemsUtil.isBind(loc1)) 
            {
                this._txtBindTips.visible = true;
            }
            else 
            {
                this._txtBindTips.visible = false;
            }
            if (this._gotEquiped && loc1.posType == EPlayerItemPosType._EPlayerItemPosTypeBag) 
            {
                this._txtExchangeTips.visible = true;
            }
            else 
            {
                this._txtExchangeTips.visible = false;
            }
            this._txtExchangeTips.visible = false;
            this._txtBindTips.visible = false;
            return;
        }

        public updateData(arg1: ItemData, arg2: ItemData): void
        {
            var loc8=0;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            var loc1=RuneUtil.getRuneItemDesc(arg1);
            this._txtDesc.htmlText = Language.getStringByParam(80081, arg2.htmlName, arg1.htmlName, loc1);
            this._stuff = arg1;
            this._target = arg2;
            this.clearIconContainer();
            var loc2=Cache.instance.rune.getMyBackPackRunesByCode(arg1.itemCode);
            var loc3=Cache.instance.rune.getMyRolePackRunesByCode(arg1.itemCode);
            var loc4=RuneUtil.getBindInfoByUnBindCode(arg1.itemCode);
            var loc5=-1;
            if (loc4 && loc4.length > 0) 
            {
                loc5 = ItemInfo(loc4[0]).item.code;
            }
            if (loc5 != -1) 
            {
                loc2 = Cache.instance.rune.getMyBackPackRunesByCode(loc5).concat(loc2);
                loc3 = Cache.instance.rune.getMyRolePackRunesByCode(loc5).concat(loc3);
            }
            var loc6=RuneUtil.getSameEffectItemCode(arg1);
            if (loc3.length > 0 || loc6 > 0) 
            {
                this._gotEquiped = true;
                if ((loc9 = loc3[0] as ItemData) == null) 
                {
                    loc9 = new ItemData(loc6);
                }
                this._txtExchangeTips.htmlText = Language.getStringByParam(80089, loc9.htmlName);
                this._txtExchangeTips.visible = true;
            }
            else 
            {
                this._gotEquiped = false;
                this._txtExchangeTips.visible = false;
            }
            var loc7=loc3.concat(loc2);
            loc8 = 0;
            while (loc8 < loc7.length) 
            {
                loc10 = loc7[loc8] as ItemData;
                (loc11 = new SkillRuneComposeComfirmStuffIcon(loc10)).x = loc8 * this.Gap;
                this._iconContainer.addChild(loc11);
                if (loc8 == 0) 
                {
                    this.updateSelected(loc11);
                }
                loc11.addEventListener(flash.events.MouseEvent.CLICK, this.clickIconHandler);
                this._curIcon = loc11;
                ++loc8;
            }
            this._iconContainer.x = (323 - loc7.length * this.Gap) / 2 + 8;
            if (!(arg2.runeSwallowCodes == null) && arg2.runeSwallowCodes.length > 0 && (arg2.runeSwallowCodes.indexOf(loc5) >= 0 || arg2.runeSwallowCodes.indexOf(arg1.itemCode) >= 0)) 
            {
                this.isNull = true;
            }
            else if (loc7.length != 0) 
            {
                this.isNull = false;
            }
            else 
            {
                this.isNull = true;
            }
            return;
        }

        /* internal  */clickIconHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as SkillRuneComposeComfirmStuffIcon;
            this.updateSelected(loc1);
            return;
        }

        /* internal  */initView(): void
        {
            this._txtDesc = ObjCreate.createGTextField("", 4, 4, 360, 100, this);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            var loc1=this._txtDesc.defaultTextFormat;
            loc1.leading = 3;
            this._txtDesc.defaultTextFormat = loc1;
            this._iconContainer = new Object /* flash.display.Sprite */();
            this._iconContainer.x = 4;
            this._iconContainer.y = 45;
            this.addChild(this._iconContainer);
            this._iconContainer.visible = false;
            this._txtBindTips = ObjCreate.createGTextField("", 8, 84, 300, 20, this);
            this._txtBindTips.htmlText = Language.getString(80082);
            this._txtBindTips.visible = false;
            this._txtExchangeTips = ObjCreate.createGTextField("", 8, 101, 300, 20, this);
            this._txtExchangeTips.visible = false;
            return;
        }

        /* internal  */clearIconContainer(): void
        {
            while (this._iconContainer.numChildren > 0) 
            {
                this._iconContainer.removeChildAt(0);
            }
            return;
        }

        /* internal */ /* const */Gap: int=45;

        /* internal */ /* const */StartX: int=20;

        /* internal */ /* const */StartY: int=74;

        /* internal */ /* var */_items: Array<any>;

        /* internal */ /* var */_txtDesc: GTextFiled;

        /* internal */ /* var */_txtBindTips: GTextFiled;

        /* internal */ /* var */_txtExchangeTips: GTextFiled;

        /* internal */ /* var */_btnSwallow: GButton;

        /* internal */ /* var */_iconContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_curIcon: SkillRuneComposeComfirmStuffIcon;

        /* internal */ /* var */_stuff: ItemData;

        /* internal */ /* var */_target: ItemData;

        /* internal */ /* var */_gotEquiped: Boolean=false;

        public /* var */isNull: Boolean=true;
    }
